﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using AutoMapper;

using Infrastructure.Core.Extension;
using SMG.Domain.Model.System;
using SMG.Domain.Model.Program;
using SMG.Domain.Model.Migration;

using SMG.Application.DTO.System;
using SMG.Application.DTO.Program;
using SMG.Application.DTO.Migration;

namespace SMG.Application.Extension
{
    public static class MapperExtension
    {

        #region User
        
        public static UserDto ConvertToUserDto(this User user)
        {
            if (null == user)
                return null;

            //方法一：一一赋值
            //UserModel userModel = new UserModel();
            //return userModel;

            //方法二：autoMapper
            return Mapper.Map<User, UserDto>(user);
        }
        public static IList<UserDto> ConvertToUserDto(this IList<User> userList)
        {
            if (userList == null || !userList.Any())
                return null;

            IList<UserDto> userDtoList = new List<UserDto>();
            userList.ForEach(user =>
            {
                userDtoList.Add(user.ConvertToUserDto());
            });

            return userDtoList;
        }

        public static User ConvertToUser(this UserDto userDto) {
            if (userDto == null)
                return null;

            return Mapper.Map<UserDto, User>(userDto);
        }
        public static IList<User> ConvertToUser(this IList<UserDto> userDtos) {
            if (userDtos == null || !userDtos.Any())
                return null;

            IList<User> userList = new List<User>();
            userDtos.ForEach(userDto =>
            {
                userList.Add(userDto.ConvertToUser());
            });

            return userList;
        }

        #endregion      

        #region Program

        public static ProgramBillDto ConvertToProgramBillDto(this ProgramBill bill)
        {
            if (null == bill)
                return null;

            //方法一：一一赋值
            //UserModel userModel = new UserModel();
            //return userModel;

            //方法二：autoMapper
            return Mapper.Map<ProgramBill, ProgramBillDto>(bill);
        }
        public static IList<ProgramBillDto> ConvertToProgramBillDto(this IList<ProgramBill> bills)
        {
            if (bills == null || !bills.Any())
                return null;

            IList<ProgramBillDto> billDtos = new List<ProgramBillDto>();
            bills.ForEach(bill =>
            {
                billDtos.Add(bill.ConvertToProgramBillDto());
            });

            return billDtos;
        }

        public static ProgramBill ConvertToBill(this ProgramBillDto billDto)
        {
            if (billDto == null)
                return null;

            return Mapper.Map<ProgramBillDto, ProgramBill>(billDto);
        }
        public static IList<ProgramBill> ConvertToBill(this IList<ProgramBillDto> billDtos)
        {
            if (billDtos == null || !billDtos.Any())
                return null;

            IList<ProgramBill> bills = new List<ProgramBill>();
            billDtos.ForEach(billDto =>
            {
                bills.Add(billDto.ConvertToBill());
            });

            return bills;
        }

        public static BillVersionRecordDto ConvertToBillVersionDto(this BillVersionRecord billVersion)
        {
            if (null == billVersion)
                return null;

            return Mapper.Map<BillVersionRecord, BillVersionRecordDto>(billVersion);
        }
        public static IList<BillVersionRecordDto> ConvertToBillVersionDto(this IList<BillVersionRecord> billVersions)
        {
            if (billVersions == null || !billVersions.Any())
                return null;

            IList<BillVersionRecordDto> billVersionDtos = new List<BillVersionRecordDto>();
            billVersions.ForEach(billVersion =>
            {
                billVersionDtos.Add(billVersion.ConvertToBillVersionDto());
            });

            return billVersionDtos;
        }

        public static BillVersionRecord ConvertToBillVersion(this BillVersionRecordDto billVersionDto)
        {
            if (null == billVersionDto)
                return null;

            return Mapper.Map<BillVersionRecordDto, BillVersionRecord>(billVersionDto);
        }
        public static IList<BillVersionRecord> ConvertToBillVersion(this IList<BillVersionRecordDto> billVersionDtos)
        {
            if (billVersionDtos == null || !billVersionDtos.Any())
                return null;

            IList<BillVersionRecord> billVersions = new List<BillVersionRecord>();
            billVersionDtos.ForEach(dto =>
            {
                billVersions.Add(dto.ConvertToBillVersion());
            });

            return billVersions;
        }

        #endregion

        #region SysDict

        public static SysDictDto ConvertToDictDto(this SysDict dict)
        {
            if (null == dict)
                return null;

            //方法二：autoMapper
            return Mapper.Map<SysDict, SysDictDto>(dict);
        }
        public static IList<SysDictDto> ConvertToDictDto(this IList<SysDict> dicts)
        {
            if (dicts == null || !dicts.Any())
                return null;

            IList<SysDictDto> dictDtos = new List<SysDictDto>();
            dicts.ForEach(bill =>
            {
                dictDtos.Add(bill.ConvertToDictDto());
            });

            return dictDtos;
        }

        public static SysDict ConvertToDict(this SysDictDto dictDto)
        {
            if (null == dictDto)
                return null;

            //方法二：autoMapper
            return Mapper.Map<SysDictDto, SysDict>(dictDto);
        }
        public static IList<SysDict> ConvertToDict(this IList<SysDictDto> dictDtos)
        {
            if (dictDtos == null || !dictDtos.Any())
                return null;

            IList<SysDict> dicts = new List<SysDict>();
            dictDtos.ForEach(dict =>
            {
                dicts.Add(dict.ConvertToDict());
            });

            return dicts;
        }

        #endregion

        #region PlayRecord

        public static PlayRecordDto ConvertToPlayRecordDto(this PlayRecord playRecord)
        {
            if (null == playRecord)
                return null;

            //方法二：autoMapper
            return Mapper.Map<PlayRecord, PlayRecordDto>(playRecord);
        }
        public static IList<PlayRecordDto> ConvertToPlayRecordDto(this IList<PlayRecord> playRecords)
        {
            if (playRecords == null || !playRecords.Any())
                return null;

            IList<PlayRecordDto> playDtos = new List<PlayRecordDto>();
            playRecords.ForEach(play =>
            {
                playDtos.Add(play.ConvertToPlayRecordDto());
            });

            return playDtos;
        }

        public static PlayRecord ConvertToPlayRecord(this PlayRecordDto playRecordDto)
        {
            if (null == playRecordDto)
                return null;

            //方法二：autoMapper
            return Mapper.Map<PlayRecordDto, PlayRecord>(playRecordDto);
        }
        public static IList<PlayRecord> ConvertToPlayRecord(this IList<PlayRecordDto> playRecordDtos)
        {
            if (playRecordDtos == null || !playRecordDtos.Any())
                return null;

            IList<PlayRecord> plays = new List<PlayRecord>();
            playRecordDtos.ForEach(dto =>
            {
                plays.Add(dto.ConvertToPlayRecord());
            });

            return plays;
        }

        #endregion

        #region FirstMoveTask

        public static FirstMoveTaskDto ConvertToDto(this FirstMoveTask firstTask)
        {
            if (null == firstTask)
                return null;

            //方法二：autoMapper
            return Mapper.Map<FirstMoveTask, FirstMoveTaskDto>(firstTask);
        }
        public static IList<FirstMoveTaskDto> ConvertToDto(this IList<FirstMoveTask> firstTasks)
        {
            if (firstTasks == null || !firstTasks.Any())
                return null;

            IList<FirstMoveTaskDto> dtos = new List<FirstMoveTaskDto>();
            firstTasks.ForEach(dto =>
            {
                dtos.Add(dto.ConvertToDto());
            });

            return dtos;
        }

        public static FirstMoveTask ConvertToDomain(this FirstMoveTaskDto dto)
        {
            if (null == dto)
                return null;

            //方法二：autoMapper
            return Mapper.Map<FirstMoveTaskDto, FirstMoveTask>(dto);
        }
        public static IList<FirstMoveTask> ConvertToDomain(this IList<FirstMoveTaskDto> dtos)
        {
            if (dtos == null || !dtos.Any())
                return null;

            IList<FirstMoveTask> tasks = new List<FirstMoveTask>();
            dtos.ForEach(dto =>
            {
                tasks.Add(dto.ConvertToDomain());
            });

            return tasks;
        }

        #endregion

        #region FirstMoveTaskDetail

        public static FirstMoveTaskDetailDto ConvertToDto(this FirstMoveTaskDetail taskDetail)
        {
            if (null == taskDetail)
                return null;

            //方法二：autoMapper
            return Mapper.Map<FirstMoveTaskDetail, FirstMoveTaskDetailDto>(taskDetail);
        }
        public static IList<FirstMoveTaskDetailDto> ConvertToDto(this IList<FirstMoveTaskDetail> taskDetails)
        {
            if (taskDetails == null || !taskDetails.Any())
                return null;

            IList<FirstMoveTaskDetailDto> dtos = new List<FirstMoveTaskDetailDto>();
            taskDetails.ForEach(dto =>
            {
                dtos.Add(dto.ConvertToDto());
            });

            return dtos;
        }

        public static FirstMoveTaskDetail ConvertToDomain(this FirstMoveTaskDetailDto dto)
        {
            if (null == dto)
                return null;

            //方法二：autoMapper
            return Mapper.Map<FirstMoveTaskDetailDto, FirstMoveTaskDetail>(dto);
        }
        public static IList<FirstMoveTaskDetail> ConvertToDomain(this IList<FirstMoveTaskDetailDto> dtos)
        {
            if (dtos == null || !dtos.Any())
                return null;

            IList<FirstMoveTaskDetail> taskDetails = new List<FirstMoveTaskDetail>();
            dtos.ForEach(dto =>
            {
                taskDetails.Add(dto.ConvertToDomain());
            });

            return taskDetails;
        }

        #endregion

        #region FirstMoveTaskState

        public static FirstMoveTaskStateDto ConvertToDto(this FirstMoveTaskState model)
        {
            if (null == model)
                return null;

            //方法二：autoMapper
            return Mapper.Map<FirstMoveTaskState, FirstMoveTaskStateDto>(model);
        }
        public static IList<FirstMoveTaskStateDto> ConvertToDto(this IList<FirstMoveTaskState> models)
        {
            if (models == null || !models.Any())
                return null;

            IList<FirstMoveTaskStateDto> dtos = new List<FirstMoveTaskStateDto>();
            models.ForEach(dto =>
            {
                dtos.Add(dto.ConvertToDto());
            });

            return dtos;
        }

        public static FirstMoveTaskState ConvertToDomain(this FirstMoveTaskStateDto dto)
        {
            if (null == dto)
                return null;

            //方法二：autoMapper
            return Mapper.Map<FirstMoveTaskStateDto, FirstMoveTaskState>(dto);
        }
        public static IList<FirstMoveTaskState> ConvertToDomain(this IList<FirstMoveTaskStateDto> dtos)
        {
            if (dtos == null || !dtos.Any())
                return null;

            IList<FirstMoveTaskState> models = new List<FirstMoveTaskState>();
            dtos.ForEach(dto =>
            {
                models.Add(dto.ConvertToDomain());
            });

            return models;
        }

        #endregion

        #region FirstMoveTaskDetailState

        public static FirstMoveTaskDetailStateDto ConvertToDto(this FirstMoveTaskDetailState model)
        {
            if (null == model)
                return null;

            //方法二：autoMapper
            return Mapper.Map<FirstMoveTaskDetailState, FirstMoveTaskDetailStateDto>(model);
        }
        public static IList<FirstMoveTaskDetailStateDto> ConvertToDto(this IList<FirstMoveTaskDetailState> models)
        {
            if (models == null || !models.Any())
                return null;

            IList<FirstMoveTaskDetailStateDto> dtos = new List<FirstMoveTaskDetailStateDto>();
            models.ForEach(dto =>
            {
                dtos.Add(dto.ConvertToDto());
            });

            return dtos;
        }

        public static FirstMoveTaskDetailState ConvertToDomain(this FirstMoveTaskDetailStateDto dto)
        {
            if (null == dto)
                return null;

            //方法二：autoMapper
            return Mapper.Map<FirstMoveTaskDetailStateDto, FirstMoveTaskDetailState>(dto);
        }
        public static IList<FirstMoveTaskDetailState> ConvertToDomain(this IList<FirstMoveTaskDetailStateDto> dtos)
        {
            if (dtos == null || !dtos.Any())
                return null;

            IList<FirstMoveTaskDetailState> models = new List<FirstMoveTaskDetailState>();
            dtos.ForEach(dto =>
            {
                models.Add(dto.ConvertToDomain());
            });

            return models;
        }

        #endregion

        #region SecondMoveTask

        public static SecondMoveTaskDto ConvertToDto(this SecondMoveTask secondTask)
        {
            if (null == secondTask)
                return null;

            //方法二：autoMapper
            return Mapper.Map<SecondMoveTask, SecondMoveTaskDto>(secondTask);
        }
        public static IList<SecondMoveTaskDto> ConvertToDto(this IList<SecondMoveTask> tasks)
        {
            if (tasks == null || !tasks.Any())
                return null;

            IList<SecondMoveTaskDto> dtos = new List<SecondMoveTaskDto>();
            tasks.ForEach(dto =>
            {
                dtos.Add(dto.ConvertToDto());
            });

            return dtos;
        }

        public static SecondMoveTask ConvertToDomain(this SecondMoveTaskDto dto)
        {
            if (null == dto)
                return null;

            //方法二：autoMapper
            return Mapper.Map<SecondMoveTaskDto, SecondMoveTask>(dto);
        }
        public static IList<SecondMoveTask> ConvertToDomain(this IList<SecondMoveTaskDto> dtos)
        {
            if (dtos == null || !dtos.Any())
                return null;

            IList<SecondMoveTask> tasks = new List<SecondMoveTask>();
            dtos.ForEach(dto =>
            {
                tasks.Add(dto.ConvertToDomain());
            });

            return tasks;
        }

        #endregion

        #region SecondMoveTaskDetail

        public static SecondMoveTaskDetailDto ConvertToDto(this SecondMoveTaskDetail taskDetail)
        {
            if (null == taskDetail)
                return null;

            //方法二：autoMapper
            return Mapper.Map<SecondMoveTaskDetail, SecondMoveTaskDetailDto>(taskDetail);
        }
        public static IList<SecondMoveTaskDetailDto> ConvertToDto(this IList<SecondMoveTaskDetail> taskDetails)
        {
            if (taskDetails == null || !taskDetails.Any())
                return null;

            IList<SecondMoveTaskDetailDto> dtos = new List<SecondMoveTaskDetailDto>();
            taskDetails.ForEach(dto =>
            {
                dtos.Add(dto.ConvertToDto());
            });

            return dtos;
        }

        public static SecondMoveTaskDetail ConvertToDomain(this SecondMoveTaskDetailDto dto)
        {
            if (null == dto)
                return null;

            //方法二：autoMapper
            return Mapper.Map<SecondMoveTaskDetailDto, SecondMoveTaskDetail>(dto);
        }
        public static IList<SecondMoveTaskDetail> ConvertToDomain(this IList<SecondMoveTaskDetailDto> dtos)
        {
            if (dtos == null || !dtos.Any())
                return null;

            IList<SecondMoveTaskDetail> taskDetails = new List<SecondMoveTaskDetail>();
            dtos.ForEach(dto =>
            {
                taskDetails.Add(dto.ConvertToDomain());
            });

            return taskDetails;
        }

        #endregion

        #region Channel

        public static ChannelDto ConvertToDto(this Channel model)
        {
            if (null == model)
                return null;

            //方法二：autoMapper
            return Mapper.Map<Channel, ChannelDto>(model);
        }
        public static IList<ChannelDto> ConvertToDto(this IList<Channel> models)
        {
            if (models == null || !models.Any())
                return null;

            IList<ChannelDto> dtos = new List<ChannelDto>();
            models.ForEach(dto =>
            {
                dtos.Add(dto.ConvertToDto());
            });

            return dtos;
        }

        public static Channel ConvertToDomain(this ChannelDto dto)
        {
            if (null == dto)
                return null;

            //方法二：autoMapper
            return Mapper.Map<ChannelDto, Channel>(dto);
        }
        public static IList<Channel> ConvertToDomain(this IList<ChannelDto> dtos)
        {
            if (dtos == null || !dtos.Any())
                return null;

            IList<Channel> models = new List<Channel>();
            dtos.ForEach(dto =>
            {
                models.Add(dto.ConvertToDomain());
            });

            return models;
        }

        #endregion

        #region Device

        public static DeviceDto ConvertToDto(this Device model)
        {
            if (null == model)
                return null;

            //方法二：autoMapper
            return Mapper.Map<Device, DeviceDto>(model);
        }
        public static IList<DeviceDto> ConvertToDto(this IList<Device> models)
        {
            if (models == null || !models.Any())
                return null;

            IList<DeviceDto> dtos = new List<DeviceDto>();
            models.ForEach(dto =>
            {
                dtos.Add(dto.ConvertToDto());
            });

            return dtos;
        }

        public static Device ConvertToDomain(this DeviceDto dto)
        {
            if (null == dto)
                return null;

            //方法二：autoMapper
            return Mapper.Map<DeviceDto, Device>(dto);
        }
        public static IList<Device> ConvertToDomain(this IList<DeviceDto> dtos)
        {
            if (dtos == null || !dtos.Any())
                return null;

            IList<Device> models = new List<Device>();
            dtos.ForEach(dto =>
            {
                models.Add(dto.ConvertToDomain());
            });

            return models;
        }

        #endregion

    }
}
